﻿using Microsoft.Practices.Unity.InterceptionExtension;
using WDA.Core;
using Microsoft.Practices.Unity;
using System.Diagnostics;

namespace Sample
{   
   public class SimpleMonitorInterceptor : ICallHandler
   {      
      [Dependency(WDAContainerNames.InternalContainerName)]
      public IUnityContainer Container { get; set; }
                 
      #region ICallHandler Members
      public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
      {         
         IMonitor monitor = Container.Resolve<IMonitor>(input.GetServiceName());
         Stopwatch sw = new Stopwatch();
         sw.Start();
         IMethodReturn result = getNext()(input, getNext);
         sw.Stop();
         monitor.RegisterOperationTime(sw.Elapsed);
         return result;
      }
      public int Order { get; set; }      
      #endregion
   }
}
